#
# tf ust linear regression
#
import tensorflow as tf
W=tf.Variable(tf.random_normal([1]),name='weight')
b=tf.Variable(tf.random_normal([1]),name='bias')

X=tf.placeholder(tf.float32,shape=[None])
Y=tf.placeholder(tf.float32,shape=[None])

#模型
hypothesis=X*W+b
#成本函数
cost=tf.reduce_mean(tf.square(hypothesis-Y))
#优化器，梯度下降优化，0.01速率
optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.01)
#最小化成本
train=optimizer.minimize(cost)

sess=tf.Session()
sess.run(tf.global_variables_initializer())

#训练
for step in range(2001):
    cost_val,W_val,b_val,_=sess.run([cost,W,b,train],feed_dict={X:[1,2,3,5],Y:[5,8,11,17]})
    if step%20==0:
        print(step,cost_val,W_val,b_val)
